package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.clientCenter.queryBean.UserInfoQueryBean;
import com.koron.css2.clientCenter.vo.UserInfoSelectVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;


/**
 * 客户快捷查询 用户编号 旧用户编号 手机号 银行账号
 * 
 * @author RealJH
 *
 */
public class UserInfoSelect implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			UserInfoQueryBean uiqBean = JsonUtils.objectToPojo(req.getData(), UserInfoQueryBean.class);
			UserInfoMapper uiMapper = factory.getMapper(UserInfoMapper.class);
			if(uiqBean!=null && StringUtils.isNotEmpty(uiqBean.getSortNo())) {
				String userNo = uiMapper.getUserNoBySortNo(uiqBean);
				if(StringUtils.isEmpty(userNo)) {
					String msg = uiqBean.getSortFlag()==0?"没有上一户了!":"没有下一户了!";
					return MessageBean.create(Constant.ILLEGAL_PARAMETER, msg, void.class);
				}
				uiqBean.setFuzzyQuery(userNo);
			}
			//PageHelper.startPage(uiqBean.getPage(), uiqBean.getPageCount());
			// 获取客户列表
			List<UserInfoSelectVo> uiList = uiMapper.userInfoSelect(uiqBean);
			Map<String, String> BPW = Tools.mapDicByCode(factory, "BPW");
			Map<String,String> CUS = Tools.mapDicByCode(factory, "CUS");
			if(uiList!=null && uiList.size()>0) {
				for(UserInfoSelectVo vo:uiList) {
					if(!StringUtils.isBlank(vo.getPayWay())) {
						vo.setPayWay(BPW.get(vo.getPayWay()));
					}
					if(!StringUtils.isBlank(vo.getStatus())) {
						vo.setStatus(CUS.get(vo.getStatus()));
					}
				}
			}
			
			@SuppressWarnings("rawtypes")
			MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", List.class);
			info.setData(uiList);
			return info;
		} catch (Exception e) {
			logger.error("客户管理列表查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
